//
//  InfoDetail.m
//  Trading365
//
//  Created by Jason on 12-2-3.
//  Copyright (c) 2012年 dhc. All rights reserved.
//

#import "QuotationInfo0.h"
#import "InfoType.h"
#import "TaskManager.h"
#import "XmlRpc.h"
#import "QuotationBar.h"


@implementation QuotationInfo0
@synthesize table;
@synthesize InfoListTitle,InfoListName;
@synthesize responseParam;
@synthesize quotationID0;


#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.title=self.key_name;
    self.table.backgroundColor=BACKGROUND_COLOR;

    NSArray *title_array = [[NSArray alloc] initWithObjects:@"报价单编号",@"客户",@"商机名称",@"联系人",@"电话",@"报价日期",@"截止日期",nil];
    self.InfoListTitle = title_array; 
    [title_array release];
    NSArray *name_title = [[NSArray alloc] initWithObjects:@"price_quote_no",@"customer_short_name",@"chance_source",@"contact_id",@"contact_phone",@"quote_date",@"quote_date",nil];
    self.InfoListName = name_title; 
    [name_title release];
    
    [self.table reloadData];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    
    [[[TaskManager Share] GetTaskByType:GetQuotationInfo0 Delegate:self] cancel];
}

- (void)dealloc {
    [responseParam release];
    [InfoListTitle release];
    [InfoListName release];
    [quotationID0 release];
    [table release];
    [super dealloc];
}



- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.InfoListTitle count];    
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    return @"";
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease];
    }
    
    // Configure the cell...
    cell.contentView.backgroundColor = [UIColor clearColor];
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView.backgroundColor = [UIColor clearColor];
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
    
    NSUInteger row = [indexPath row];
//    if ([responseParam count] < 1)
//        return cell;

    cell.imageView.image = nil;
    cell.textLabel.text = [self.InfoListTitle objectAtIndex:row];
    cell.detailTextLabel.text =[responseParam objectForKey:[self.InfoListName objectAtIndex:row]];
    cell.accessoryType = UITableViewCellAccessoryNone;
                
    return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Navigation logic may go here. Create and push another view controller.  
    
//    ProductInfoDetail *info = [[ProductInfoDetail alloc] init];
//    [info setInfoDetail:responseParam];
//    [self.navigationController pushViewController:info animated:YES];
//    [info release];
     
}

- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{    
    return nil;
}


#pragma mark - 
#pragma mark - my func

-(void) OnPreExcute
{
    [super OnPreExcute];
}

-(void) DoInBackground
{
    XmlRpc *xml = [[XmlRpc alloc] init];
    NSMutableDictionary *tmp;

    tmp = [xml GetQuotationBasic:self.quotationID0];
    
    responseParam = [[NSMutableDictionary alloc] initWithDictionary:tmp];
    
    [xml release];
    [self.table reloadData];
}

-(void) OnPostExcute
{
    [super OnPostExcute];
    self.quotationInfo.navigationItem.leftBarButtonItem.enabled=YES;
    
}

-(void)refreshData
{    
    [[[TaskManager Share] GetTaskByType:GetQuotationInfo0 Delegate:self] Excute];
}

@end
